/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slisfx.devices;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import slisfx.Globals;
import slisfx.resources.Load;
import slisfx.screens.DeviceViewAdminFX;

/**
 *
 * @author ITC
 */
public class ThermoViewAdminFX extends Application implements Globals  {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    
     
    @Override
    public void start(final Stage primaryStage) {
        try {
            primaryStage.setTitle("Thermostat View");
           primaryStage.setResizable(false);
         
           
            /*
              * Here we will declare all the functions for our Screen.
              */
             
             /*
              *THIS IS THE CORRECT WAY TO CALL AN IMAGE FROM A PACKAGE
              *VERY EASY UNLIKE EVERY FOURM SAYS!
              */
             
             Image image = new Image(new Load().loadFile("gray.png"));
             Image image1 = new Image(new Load().loadFile("NASA_IVV1_sm.png"));
             Image image2 = new Image(new Load().loadFile("WVU_LOGO_sm.png"));

             BorderPane mainWindow = new BorderPane();
             
             
             
             mainWindow.setTop(new Rectangle(830,50, Color.BLACK));
             mainWindow.setBottom(new Rectangle(830,50, Color.BLACK));
             mainWindow.setLeft(new Rectangle(50,350, Color.BLACK));
             mainWindow.setRight(new Rectangle(50, 350, Color.BLACK));
             
             //This is for the background
             StackPane stackPane = new StackPane();
             
            //This is for horizantal layout.
            HBox imageBox = new HBox();
            imageBox.setPadding(new Insets(10, 10, 10, 200));
            imageBox.setSpacing(100);
             
             //This is a function for Images
             ImageView iv1BackGround = new ImageView();
             ImageView iv2 = new ImageView();
             ImageView iv3 = new ImageView();
             iv1BackGround.setImage(image);
             iv2.setImage(image1);
             iv3.setImage(image2);
             
             imageBox.getChildren().addAll(iv2, iv3);
             
     //        Slider slider = new Slider(0, 1, 0.5);
     //        slider.setShowTickMarks(true);
     //        slider.setShowTickLabels(true);
     //        slider.setMajorTickUnit(0.25f);
     //        slider.setBlockIncrement(0.1f);
            
             Text currentTemp = new Text("Current Room Temp is " + x10.getRoomTemp() + "F");
             currentTemp.setFont(Font.font("Amble CN", FontWeight.BOLD, 18));
             currentTemp.setFill(Color.WHITE);
             final Text currentSetTemp = new Text("Current Set Temp is " + x10.getSetTemp() + "F");
             currentSetTemp.setFont(Font.font("Amble CN", FontWeight.BOLD, 18));
             currentSetTemp.setFill(Color.WHITE);
             Text space = new Text("             ");
             space.setFont(Font.font("Amble CN", FontWeight.BOLD, 18));
             space.setFill(Color.WHITE);
             Button btn = new Button();
             Button btn2 = new Button();
             Button btn3 = new Button();
             Button btn4 = new Button();
             Button btn5 = new Button();
             Button btn6 = new Button();
             
         
             btn.setText("Off");
             btn.setOnAction(new EventHandler<ActionEvent>() {

                 @Override
                 public void handle(ActionEvent event) {
                     System.out.println("Thermo Off");
                     x10.thermo(3);
                 }
              });
             
             btn2.setText("Heat");
             btn2.setOnAction(new EventHandler<ActionEvent>() {

                 @Override
                 public void handle(ActionEvent event) {
                     System.out.println("Heating selected");
                     x10.thermo(1);
                 }
              });
             
             btn3.setText("Cool");
             btn3.setOnAction(new EventHandler<ActionEvent>() {

                 @Override
                 public void handle(ActionEvent event) {
                     System.out.println("Cooling Selected");
                     x10.thermo(2);
                 }
              });
             
             btn4.setText("Increase");
             btn4.setOnAction(new EventHandler<ActionEvent>() {

                 @Override
                 public void handle(ActionEvent event) {
                     System.out.println("Increase Temp");
                     x10.thermo(4);
                     try {
            Thread.sleep(200); 
        } catch (Exception e) {}
                     currentSetTemp.setText("Current Set Temp is " + x10.getSetTemp() + "F");
                 }
              });
               
             btn5.setText("Decrease");
             btn5.setOnAction(new EventHandler<ActionEvent>() {

                 @Override
                 public void handle(ActionEvent event) {
                     System.out.println("Decrease Temp");
                     x10.thermo(5);
                     try {
            Thread.sleep(200); 
        } catch (Exception e) {}
                     currentSetTemp.setText("Current Set Temp is " + x10.getSetTemp() + "F");
                 }
              });
             
             
             btn6.setText("Return");
             btn6.setOnAction(new EventHandler<ActionEvent>() {

                 @Override
                 public void handle(ActionEvent event) {
                     new DeviceViewAdminFX().start(primaryStage);
                 }
              });
   
             HBox ckboxes = new HBox();
             ckboxes.setPadding(new Insets(10, 10, 10, 10));
             ckboxes.setSpacing(20);
             
             HBox onOffBut = new HBox();
             onOffBut.setPadding(new Insets(10, 10, 10, 75));
             onOffBut.setSpacing(50);
             onOffBut.getChildren().add(btn);
             onOffBut.getChildren().add(btn2);
             onOffBut.getChildren().add(btn3);
             onOffBut.getChildren().add(btn4);
             onOffBut.getChildren().add(btn5);
             onOffBut.getChildren().add(btn6);

     //        HBox dimOrBright = new HBox();
     //        onOffBut.setPadding(new Insets(10, 10, 10, 10));
     //        onOffBut.setSpacing(50);
     //        onOffBut.getChildren().add(btn3);
     //        onOffBut.getChildren().add(btn4);
             
             HBox currentInfo = new HBox();
             currentInfo.setPadding(new Insets(10, 10, 10, 75));
             currentInfo.setSpacing(50);
             currentInfo.getChildren().add(currentTemp);
             currentInfo.getChildren().add(space);
             currentInfo.getChildren().add(currentSetTemp);
             
             VBox mainMenu = new VBox();
             mainMenu.setPadding(new Insets(10, 10, 10, 10));
             mainMenu.setSpacing(10);
             Text title = new Text("Thermostat menu");
             title.setFont(Font.font("Amble CN", FontWeight.BOLD, 14));
             title.setFill(Color.WHITE);
             mainMenu.getChildren().addAll(title, imageBox, ckboxes);
             //mainMenu.getChildren().add(slider);
             //mainMenu.getChildren().add(dimOrBright);
             mainMenu.getChildren().add(onOffBut);
             mainMenu.getChildren().add(currentInfo);
             
             stackPane.getChildren().addAll(iv1BackGround, mainMenu);
             mainWindow.setCenter(stackPane);

             primaryStage.setScene(new Scene(mainWindow, WIDTH, HEIGHT));
             primaryStage.show();
        } catch (IOException ex) {
            Logger.getLogger(ThermoViewAdminFX.class.getName()).log(Level.SEVERE, null, ex);
        }
        
       
    }
}
